package auth

import (
	"context"
	"go.uber.org/zap"
	"navi-mumbai/app/rpc/game/pb"

	"navi-mumbai/app/api/game/internal/svc"
	"navi-mumbai/app/api/game/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RefreshUserGameTokenLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRefreshUserGameTokenLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RefreshUserGameTokenLogic {
	return &RefreshUserGameTokenLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RefreshUserGameTokenLogic) RefreshUserGameToken(req *types.GenUserGameTokenReq) (resp *types.GenUserGameTokenResp, err error) {
	var in pb.GenGameTokenReq
	in.OpenId = req.OpenId
	in.ProviderId = req.ProviderId
	var rsp *pb.GenGameTokenResp
	rsp, err = l.svcCtx.GameUserRpc.GenGameToken(l.ctx, &in)
	if err != nil {
		l.Logger.Errorf("err == ", zap.Error(err))
		return nil, err
	}
	resp = &types.GenUserGameTokenResp{}
	resp.Token = rsp.Token
	return
}
